<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>主页</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
    <link rel="stylesheet" th:href="@{/css/bootstrap.min.css}" />
    <script th:src="@{/js/vue.js}"></script>
</head>
<div th:insert="publicHesder"></div>
<script th:src="@{/js/publicHeader.js}"></script>
<body>
<div class="container-fluid" id="app" style="margin-top: 180px;margin-bottom: 100px">

    <div class="container">

        <div class="row">
            <div class="col-md-12">
                <p style="background-color: cornflowerblue ; color: white; font-size: 30px">商品概览</p>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-6 col-md-4" v-for="p in product">
                <div class="thumbnail">
                    <img src="" alt="..." class="col-sm-6 col-md-6">
                    <div class="caption text-left">
                        <p>商品名:<span v-text="p.productname">name</span></p>
                        <p>价格:<span v-text="p.productprice">price</span></p>
                        <p>
<!--                            <a class="btn btn-primary" href="">详情</a> &nbsp;&nbsp;&nbsp;&nbsp;-->
                            <a class="btn btn-success" href="">加入购物车</a>
                        </p>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12 col-md-offset-5 col-lg-offset-4col-xl-offset-5" >
                <ul class="pagination justify-content-center">
                    <li><a href="javascript:void(0)" @click.prevent="go(currentPage-1)">&laquo;</a></li>
                    <li><a href="javascript:void(0)" v-for="n in totalPage" v-text="n" @click.prevent="go(n)">n</a></li>
                    <li><a href="javascript:void(0)" @click.prevent="go(currentPage+1)">&raquo;</a></li>
                </ul>
            </div>
            当前是第{{currentPage}}页，共有{{totalPage}}页，{{total}}条记录。
        </div>

    </div>


</div>

<script>
    console.log(".........index...........")
    let index = new Vue({
        el: "#app"
        ,
        data: {
            product:[],
            currentPage:1,
            pageSize:3,
            totalPage:0,
            total:0,
            keyword:''
        }
        ,
        methods: {
            initProduct(){
                let _this = this;
                let params = {
                    currentPage: this.currentPage,
                    pageSize : this.pageSize,
                    keyword: this.keyword
                }
                console.log(this.keyword);
                $.get("/product/all",params,function (data){
                    console.log(data);
                    _this.product = data.records;
                    let records = data.records;
                    _this.currentPage = data.current;
                    _this.pageSize = records.size;
                    _this.total = data.total;
                    _this.totalPage = data.pages;
                })
            }
            ,
            go(pageNum){
                let _this = this;
                if (pageNum<1 || pageNum>this.totalPage || pageNum==this.currentPage){
                    return;
                }
                this.currentPage = pageNum;
                this.pageSize = 3;
                this.initProduct();
            }
        }
        ,
        created(){
            this.initProduct();
        }

    });
</script>
</body>
</html>